<div class="container">
    <div class="row">
        <div class="col-sm-2">
            <div class="sidebar-module sidebar-module-inset">
                <form method="post">
                    <h4 class="text-center">Filtres</h4><br>

                    <h6><i>Catégorie(s)</i></h6>

                    <?php foreach ($this->categoriesEnBase as $c) { ?>
                        <div class="checkbox">
                            <label>
                                <?php echo '<input type="checkbox" name="categories[]" value="'.$c->getId().'" ';
                                if (!empty($this->categories) && in_array($c->getId(), $this->categories)) {
                                    echo 'checked ';
                                }
                                echo '/> '.$this->escapeHtml($c->getLibelle()); ?>
                            </label>
                        </div>
                    <?php } ?>
                    <br />

                    <h6><i>État(s)</i></h6>

                    <?php foreach ($this->etatsEnBase as $e) { ?>
                        <div class="checkbox">
                            <label>
                                <?php echo '<input type="checkbox" name="etats[]" value="'.$e->getId().'" ';
                                if (!empty($this->etats) && in_array($e->getId(), $this->etats)) {
                                    echo 'checked ';
                                }
                                echo '/> '.$this->escapeHtml($e->getLibelle()); ?>
                            </label>
                        </div>
                    <?php } ?>
                    <br />

                    <h6><i>Prix</i></h6>

                    <?php // TODO : use slider. init with jquery ?>
                    <p>
                        <label>Prix minimum
                            <input type="text" class="form-control" name="prixmin" autocomplete="off" value="<?php echo $this->prixmin; ?>"/>
                        </label>
                    </p>
                    <p>
                        <label>Prix maximum
                            <input type="text" class="form-control" name="prixmax" autocomplete="off" value="<?php echo $this->prixmax; ?>"/>
                        </label>
                    </p>

                    <br />
                    <button type="submit" class="btn btn-success">
                        Actualiser <span class="glyphicon glyphicon-refresh"></span>
                    </button>
                </form>
            </div>        
        </div>
        <div class="col-sm-10 blog-main">

            <div class="col-lg-12">
                <h3><?php echo count($this->produitsEnBase); ?> produits</h3>
            </div>
    
            <?php foreach ($this->produitsEnBase as $produit) { ?>
                <div class="text-center">
                    <div class="col-lg-4 col-md-4 hero-feature">
                        <div class="thumbnail">
                            <?php
                                $display_image = 'no-preview.jpg';
                                // get the first image which exist
                                foreach ($produit->getImages() as $image) {
                                    if (file_exists($this->full_file_path.$image->getChemin())) {
                                        $display_image = $image->getChemin();
                                        break;
                                    }
                                }
                                $display_image = $this->file_path.$display_image;
                            ?>
                            <img src="<?php echo $display_image; ?>" alt="">
                            <div class="caption">
                                <h4><?php echo $this->escapeHtml($produit->getLibelle()); ?></h4>
                                <p><?php echo $this->escapeHtml($produit->getCategorie()->getLibelle()); ?></p>
                                <p><?php echo $this->escapeHtml($produit->getPrix()).' €'; ?></p>
                                <p><?php echo $this->escapeHtml($produit->getEtat()->getLibelle()); ?></p>
                                <p><a href="<?php echo $this->url('article').$produit->getId() ?>" class="btn btn-primary">Voir!</a>
                                </p>
                            </div>
                        </div>
                    </div>
                </div><!-- /.text-center -->
            <?php } ?>
        </div>
        
    </div>
</div>
